package fr.ul.ade.maquette.ui;

import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;

import fr.ul.ade.maquette.R;
import fr.ul.ade.maquette.ui.mobile.ScheduleDetails;
import fr.ul.ade.maquette.ui.util.Bundles;

/**
 * Fragment affichant les détails d'un cours.
 * 
 * @author Michaël Schnell
 * @since Jun 10, 2013
 * 
 * @version 1.0
 */
public class ScheduleDetailsFragment
		extends SherlockFragment {

	/**
	 * Identifiant de l'emploi du temps à afficher.
	 */
	int scheduleId;

	/**
	 * Crée une nouvelle instance.
	 * 
	 * @param scheduleId
	 *            identifiant de l'emploi du temps à afficher
	 * @return Instance créée
	 */
	public static ScheduleDetailsFragment newInstance(long scheduleId) {
		ScheduleDetailsFragment fragment = new ScheduleDetailsFragment();
		Bundle args = new Bundle();
		args.putLong(Bundles.SCHEDULE_ID, scheduleId);
		fragment.setArguments(args);
		return fragment;
	}

	/**
	 * Création de la vue utilisée par le fragment.
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_schedule_details,
				container,
				false);
	}

	/**
	 * Initialisation de la vue du fragment.
	 */
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		try {
			this.scheduleId = (int) ((ScheduleDetails) this.getActivity())
					.getIntent().getExtras().getLong(Bundles.SCHEDULE_ID);
		} catch (ClassCastException cce) {
			this.scheduleId = (int) this.getArguments()
					.getLong(Bundles.SCHEDULE_ID);
		}

		View view = this.getView();

		((TextView) view.findViewById(R.id.schedule_details_name))
				.setText(ScheduleData.name[this.scheduleId]);
		((TextView) view.findViewById(R.id.schedule_details_last_update))
				.setText(ScheduleData.last_update[this.scheduleId]);
		((TextView) view.findViewById(R.id.schedule_details_resources))
				.setText(ScheduleData.res[this.scheduleId]);
		((TextView) view.findViewById(R.id.schedule_details_period))
				.setText(ScheduleData.period[this.scheduleId]);
		((TextView) view.findViewById(R.id.schedule_details_project_id))
				.setText(ScheduleData.project[this.scheduleId]);
		((TextView) view.findViewById(R.id.schedule_details_created))
				.setText(ScheduleData.created[this.scheduleId]);
	}

	/**
	 * Données affichées (maquette).
	 */
	public interface ScheduleData {

		final String[] last_update = new String[] { "2013/06/08 13:35",
				"2013/05/30 15:55", "2013/06/08 13:55", "jamais" };
		final String[] name = new String[] { "Numéro étudiant", "Salles infos",
				"Master", "Très long titre pour un emploi du temps" };
		final String[] res = new String[] { "31011672", "25, 258, 2586, 25864",
				"1254, 31001672", "254, 78" };
		final String[] period = new String[] { "7", "14", "28", "150" };
		final String[] project = new String[] { "Projet principal",
				"Projet principal", "Esial", "Esial" };
		final String[] created = new String[] { "2013/05/31", "2013/05/28",
				"2013/06/01", "2013/06/07" };

	}
}